#include "ncsstringlistedit.h"
#include "dlgstringlisteditor.h"
#include "../ncspropmgr.h"

#include <QtCore/qdebug.h>

//--------------------------------------------------------------------------------------------------
NcsStringListEdit::NcsStringListEdit( NcsProp* prop, QWidget *parent)
    : QToolButton(parent)
    , m_prop(prop)
{
    Q_ASSERT(prop!=nullptr); 
    m_stringList = prop->value().value<QStringList>();
    setFocusPolicy(Qt::NoFocus);
    setText(tr("Modify String List"));
    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));

    connect(this, &QAbstractButton::clicked, this, &NcsStringListEdit::popupEditor);
}

NcsStringListEdit::~NcsStringListEdit()
{
}

void NcsStringListEdit::updateProp(const QStringList &stringList)
{
    m_prop->propMgr()->setValue(m_prop, stringList);
}

void NcsStringListEdit::popupEditor()
{
    int result;
    QStringList lst = DlgStringListEditor::getStringList(0, m_stringList, &result);
    if (result == QDialog::Accepted) {
        m_stringList = lst;
        updateProp(m_stringList);
    }
}

//--------------------------------------------------------------------------------------------------

